﻿using Shop.Collect;
using Shop.LocalEvent;
using Shop.Model.DB;
using Shop.RemoteModel.LogisticsTemplate.Model;
using Shop.Service.Interface;
using WeDonekRpc.Client;
using WeDonekRpc.Model;

namespace Shop.Service.lmpl
{
    internal class LogisticsTemplateService : ILogisticsTemplateService
    {
        private readonly ILogisticsTemplateCollect _Template;

        public LogisticsTemplateService (ILogisticsTemplateCollect template)
        {
            this._Template = template;
        }

        public long Add (LogisticsTemplateDatum datum)
        {
            return this._Template.Add(datum);
        }
        public LogisticsItem[] GetItems ()
        {
            return this._Template.GetItems();
        }
        public void Delete (long id)
        {
            DBLogisticsTemplate template = this._Template.Get(id);
            this._Template.Delete(template);
            new LogisticsTemplateEvent("Delete", template).AsyncPublic();
        }

        public LTemplateDatum Get (long id)
        {
            return this._Template.Get<LTemplateDatum>(id);
        }

        public PagingResult<LTemplateDatum> Query (LTQueryParam query, IBasicPage paging)
        {
            LTemplateDatum[] list = this._Template.Query<LTemplateDatum>(query, paging, out int count);
            return new PagingResult<LTemplateDatum>(list, count);
        }

        public bool Set (long id, LogisticsTemplateDatum datum)
        {
            DBLogisticsTemplate template = this._Template.Get(id);
            return this._Template.Set(template, datum);
        }

        public long SetIsDefault (long id)
        {
            DBLogisticsTemplate template = this._Template.Get(id);
            return this._Template.SetIsDefault(template);
        }

        public bool SetIsEnable (long id, bool isEnable)
        {
            DBLogisticsTemplate template = this._Template.Get(id);
            return this._Template.SetIsEnable(template, isEnable);
        }
    }
}
